<?php
/**
 * Created by PhpStorm.
 * User: meng
 * Date: 2023/9/5
 * Time: 14:06
 */

namespace lib\exception;

use RuntimeException;
use Webman\Config;

class BaseException extends RuntimeException
{
    public $message;

    public $code = 200;

    public $errCode = 200;

    public $data = null;

    public function __construct ($message = [], $errCode = null) {
        parent::__construct();
        if (is_string($message)) {
            $this->message = $message;
            if (isset($errCode)) {
                $this->errCode = $errCode;
            }
        } elseif (is_int($message)) {
            $this->errCode = $message;
            $codesMessages = Config::get('errorcode.admin');
            if (isset($codesMessages[$message])) {
                $this->message = $codesMessages[$message];
            }
        } elseif (is_array($message)) {
            if (array_key_exists('code', $message)) {
                $this->code = $message['code'];
            }
            if (array_key_exists('message', $message)) {
                $this->message = $message['message'];
            }
            if (array_key_exists('errCode', $message)) {
                $this->errCode = $message['errCode'];
            }
            if (array_key_exists('data', $message)) {
                $this->data = $message['data'];
            }
        }
    }


}
